﻿using ETSModel;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

/// <summary>
/// 单位生成
/// </summary>
public class UnitGenerater : MonoBehaviour
{
  public static UnitGenerater Instance;

  public GameObject boss;
  public GameObject unit;
  public Transform[] Dots;
  public int WaitTime;
  private float timer;

  private void Awake()
  {
    Instance = this;
  }

  // Use this for initialization
  void Start()
  {
    timer = WaitTime;
  }

  // Update is called once per frame
  void Update()
  {
    timer += Time.deltaTime;

    if (timer > WaitTime)
    {
      timer = 0;
      if (GameManagerComponent.Instance.Score > 500)
      {
        Create(boss);
        return;
      }
      Create(unit);
    }
  }

  void Create(GameObject unit)
  {
    GameObject gameObject = Instantiate(unit);
    System.Random random = new System.Random();
    int index = random.Next(0, Dots.Length);
    gameObject.transform.position = Dots[index].position;
  }
}